package com.pug.config.middle.listerner;

import com.pug.event.MongoEvent;
import com.pug.service.message.MongoDbMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022/3/27$ 1:18$
 */
@Component
@Slf4j
public class MongoDbMessageListerner implements SmartApplicationListener {

    @Autowired
    public MongoDbMessageService mongoDbMessageService;

    @Override
    public int getOrder() {
        return 1;
    }


    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if(event.getClass() == MongoEvent.class){
            MongoEvent mongoEvent = (MongoEvent)event;
            mongoDbMessageService.saveMongoMessage(mongoEvent);
            log.info("MongoEvent -----------> 保存订单消息成功!!!!");
        }
    }

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return true;
    }
}

